"""Implement a custom 'translate' tag that uses our own dicts (which in turn are imported from Google trixes).

Django's inbuilt tag uses Unix .po files which are way neckbeardy, so we use this instead.
"""

from django import template
register = template.Library()
import logging

@register.simple_tag(takes_context=True)
def translate(context, something_to_translate):
    '''A Django 'simple tag' version of the translation
    From django docs: The first argument *must* be called "context" here.'''
    translator = context.get('translator')
    if not translator:
        raise ValueError('Please add a Translator object to your template_vars')
    translation = translator.translate(something_to_translate)
    if not translation:
        logging.debug('Missing translation for "%s", returning untranslated string' % (something_to_translate))
        translation = something_to_translate
    return translation
